import tseslint from '@electron-toolkit/eslint-config-ts';
import eslintConfigPrettier from '@electron-toolkit/eslint-config-prettier';
import eslintPluginVue from 'eslint-plugin-vue';
import vueParser from 'vue-eslint-parser';
import { resolveConfigFile, loadConfig } from 'prettier';

let prettierOptions = {};
try {
  const configFile = await resolveConfigFile(process.cwd());
  if (configFile) {
    prettierOptions = (await loadConfig(configFile)) || {};
  }
} catch (error) {
  console.error('加载 Prettier 配置失败:', error);
}

export default tseslint.config(
  { ignores: ['**/node_modules', '**/dist', '**/out'] },
  tseslint.configs.recommended,
  eslintPluginVue.configs['flat/recommended'],
  {
    files: ['**/*.vue'],
    languageOptions: {
      parser: vueParser,
      parserOptions: {
        ecmaFeatures: {
          jsx: true
        },
        extraFileExtensions: ['.vue'],
        parser: tseslint.parser
      }
    }
  },
  {
    files: ['**/*.{ts,mts,tsx,vue}'],
    rules: {
      'vue/require-default-prop': 'off',
      'vue/multi-word-component-names': 'off',
      'vue/block-lang': [
        'error',
        {
          script: {
            lang: 'ts'
          }
        }
      ]
    }
  },
  eslintConfigPrettier({
    rules: {
      // semi: false,
      // singleQuote: true,
      // trailingComma: 'none',
      // printWidth: 100,
      // endOfLine: 'auto',
      ...prettierOptions
    }
  })
);
